import { ApiProperty } from '@midwayjs/swagger';
import { getSchema, Rule, RuleType } from '@midwayjs/validate';
import { alternatives, StrIdNullValidator } from '..';
import { MenusSchema } from '../../schema';

export class SaveMenusValidator implements MenusSchema {
  @ApiProperty({
    type: StrIdNullValidator,
    title: '父级菜单',
    example: 'null',
    description: '父级菜单',
    required: true,
  })
  @Rule(getSchema(StrIdNullValidator).allow())
  parent: MenusSchema;

  @ApiProperty({
    type: 'string',
    title: '路由访问路径',
    example: 'null',
    description: '路由访问路径',
    required: true,
  })
  @Rule(RuleType.string().required())
  path: string;

  @ApiProperty({
    type: 'string',
    title: '路由名称（唯一）',
    example: 'null',
    description: '路由名称（唯一）',
    required: true,
  })
  @Rule(RuleType.string().required())
  name: string;

  @ApiProperty({
    type: 'string',
    title: '路由重定向地址',
    example: 'null',
    description: '路由重定向地址',
    required: false,
  })
  @Rule(RuleType.alternatives(alternatives))
  redirect?: string;

  @ApiProperty({
    type: 'string',
    title: '视图文件路径',
    example: 'null',
    description: '视图文件路径',
    required: false,
  })
  @Rule(RuleType.alternatives(alternatives))
  component?: string;

  @ApiProperty({
    type: 'string',
    title: '菜单和面包屑对应的图标',
    example: 'null',
    description: '菜单和面包屑对应的图标',
    required: true,
  })
  @Rule(RuleType.string().required())
  icon: string;

  @ApiProperty({
    type: 'string',
    title: '路由标题',
    example: 'null',
    description: '路由标题',
    required: true,
  })
  @Rule(RuleType.string().required())
  title: string;

  @ApiProperty({
    type: 'string',
    title: '是否在菜单中隐藏, 需要高亮的 path (通常用作详情页高亮父级菜单)',
    example: 'null',
    description:
      '是否在菜单中隐藏, 需要高亮的 path (通常用作详情页高亮父级菜单)',
    required: false,
  })
  @Rule(RuleType.alternatives(alternatives))
  activeMenu?: string;

  @ApiProperty({
    type: 'string',
    title: '路由外链时填写的访问地址',
    example: 'null',
    description: '路由外链时填写的访问地址',
    required: false,
  })
  @Rule(RuleType.alternatives(alternatives))
  isLink?: string;

  @ApiProperty({
    type: 'boolean',
    title: '是否在菜单中隐藏',
    example: 'false',
    description: '是否在菜单中隐藏',
    required: false,
  })
  @Rule(RuleType.alternatives(alternatives))
  isHide?: boolean;

  @ApiProperty({
    type: 'boolean',
    title: '菜单是否全屏',
    example: 'false',
    description: '菜单是否全屏',
    required: false,
  })
  @Rule(RuleType.alternatives(alternatives))
  isFull?: boolean;

  @ApiProperty({
    type: 'boolean',
    title: '菜单是否固定在标签页中',
    example: 'false',
    description: '菜单是否固定在标签页中',
    required: false,
  })
  @Rule(RuleType.alternatives(alternatives))
  isAffix?: boolean;

  @ApiProperty({
    type: 'boolean',
    title: '当前路由是否缓存',
    example: 'true',
    description: '当前路由是否缓存',
    required: false,
  })
  @Rule(RuleType.alternatives(alternatives))
  isKeepAlive?: boolean;

  @ApiProperty({
    type: 'number',
    title: '排序',
    example: '1',
    description: '排序',
    required: false,
  })
  @Rule(RuleType.alternatives(alternatives))
  sort?: number;
}

export class EditMenusValidator implements Partial<MenusSchema> {
  @ApiProperty({
    type: StrIdNullValidator,
    title: '父级菜单',
    example: 'null',
    description: '父级菜单',
    required: true,
  })
  @Rule(getSchema(StrIdNullValidator).allow())
  parent: MenusSchema;

  @ApiProperty({
    type: 'string',
    title: '路由访问路径',
    example: 'null',
    description: '路由访问路径',
    required: false,
  })
  @Rule(RuleType.alternatives(alternatives))
  path?: string;

  @ApiProperty({
    type: 'string',
    title: '路由名称（唯一）',
    example: 'null',
    description: '路由名称（唯一）',
    required: false,
  })
  @Rule(RuleType.alternatives(alternatives))
  name?: string;

  @ApiProperty({
    type: 'string',
    title: '路由重定向地址',
    example: 'null',
    description: '路由重定向地址',
    required: false,
  })
  @Rule(RuleType.alternatives(alternatives))
  redirect?: string;

  @ApiProperty({
    type: 'string',
    title: '视图文件路径',
    example: 'null',
    description: '视图文件路径',
    required: false,
  })
  @Rule(RuleType.alternatives(alternatives))
  component?: string;

  @ApiProperty({
    type: 'string',
    title: '菜单和面包屑对应的图标',
    example: 'null',
    description: '菜单和面包屑对应的图标',
    required: false,
  })
  @Rule(RuleType.alternatives(alternatives))
  icon?: string;

  @ApiProperty({
    type: 'string',
    title: '路由标题',
    example: 'null',
    description: '路由标题',
    required: false,
  })
  @Rule(RuleType.alternatives(alternatives))
  title?: string;

  @ApiProperty({
    type: 'string',
    title: '是否在菜单中隐藏, 需要高亮的 path (通常用作详情页高亮父级菜单)',
    example: 'null',
    description:
      '是否在菜单中隐藏, 需要高亮的 path (通常用作详情页高亮父级菜单)',
    required: false,
  })
  @Rule(RuleType.alternatives(alternatives))
  activeMenu?: string;

  @ApiProperty({
    type: 'string',
    title: '路由外链时填写的访问地址',
    example: 'null',
    description: '路由外链时填写的访问地址',
    required: false,
  })
  @Rule(RuleType.alternatives(alternatives))
  isLink?: string;

  @ApiProperty({
    type: 'boolean',
    title: '是否在菜单中隐藏',
    example: 'false',
    description: '是否在菜单中隐藏',
    required: false,
  })
  @Rule(RuleType.alternatives(alternatives))
  isHide?: boolean;

  @ApiProperty({
    type: 'boolean',
    title: '菜单是否全屏',
    example: 'false',
    description: '菜单是否全屏',
    required: false,
  })
  @Rule(RuleType.alternatives(alternatives))
  isFull?: boolean;

  @ApiProperty({
    type: 'boolean',
    title: '菜单是否固定在标签页中',
    example: 'false',
    description: '菜单是否固定在标签页中',
    required: false,
  })
  @Rule(RuleType.alternatives(alternatives))
  isAffix?: boolean;

  @ApiProperty({
    type: 'boolean',
    title: '当前路由是否缓存',
    example: 'true',
    description: '当前路由是否缓存',
    required: false,
  })
  @Rule(RuleType.alternatives(alternatives))
  isKeepAlive?: boolean;

  @ApiProperty({
    type: 'number',
    title: '排序',
    example: '1',
    description: '排序',
    required: false,
  })
  @Rule(RuleType.alternatives(alternatives))
  sort?: number;
}
